from locust import FastHttpUser, task, constant


class MyTasks(FastHttpUser):
    # wait_time = constant_throughput(2000)
    # wait_time = between(1, 2)
    wait_time = constant(1)
    host = "https://www.retone-hearing.fit"
    # host = "https://192.168.10.233:8081"
    header = {"Cookie": "hearingaid_user=NmE1YWQyZmMtZGMzZC00OGU2LWI5NTgtN2IxMzNjZjRjMDQw",
              "Content-Type": "application/json"}

    @task
    def getLoginState(self):
        url = '/microServiceUser/responseEncode/requestDecode/getLoginState'
        with self.client.post(url, headers = self.header,catch_response=True) as resp:
            try:
                if resp.status_code > 400 or resp.json()['data'] == None:
                    resp.failure(f"=======错误返回:status_code={resp.status_code},resp={resp.text}==========")
                else:
                    print(resp.json())
                    resp.success()
            except:
                print('error')